package com.tboss.template.common.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;

public class CustRunningTimerAdvice {
	
	
	private static final Logger log = LoggerFactory.getLogger(CustRunningTimerAdvice.class);
	//private static final Logger log = Logger.getLogger(CustRunningTimerAdvice.class);
	
	public Object stopWatch(ProceedingJoinPoint joinPoint) throws Throwable {
		StopWatch stopWatch = new StopWatch();
		
		//HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		
		/*HttpServletRequest req = null;
		for(Object o : joinPoint.getArgs()){
			if(o instanceof XssRequestWrapper){
				req = (HttpServletRequest) o;
			}
		}*/
		
		try {
			stopWatch.start();
			Object rtnValue = joinPoint.proceed();
			return rtnValue;
			
		} catch (Throwable e) { throw e; 
		} finally {
			stopWatch.stop();
			
//			Long oneDayMillies = (long) (60*60*24*1000);
//			Long lastTaskTimeMillies = stopWatch.getLastTaskTimeMillis();
//			Long totalTimeMillies = stopWatch.getTotalTimeMillis();
			Double totalTimeSecond = stopWatch.getTotalTimeSeconds();
//			Float transSeconds = (float) (((float)totalTimeMillies/1000)*1000.0/1000.0);

			log.info(""+totalTimeSecond);
			
			/*if(!SecurityUtils.getCurrentUserName().equals("anonymousUser")){
				System.out.println(req.getSession());
				//req.getRequestDispatcher ("/").forward((ServletRequest)req, null);
				
			}*/
		}
	}

}
